package cn.wei.reallyEnjoy.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.wei.reallyEnjoy.R;
import cn.wei.reallyEnjoy.home.bean.DiaryBean;
import cn.wei.reallyEnjoy.utils.Constants;

public class SearchDiaryAdapter extends BaseAdapter {
    private List<DiaryBean> data;
    private Context context;

    public SearchDiaryAdapter(List<DiaryBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_hot_grid_view, parent, false);
        }
        ImageView iv_img = convertView.findViewById(R.id.iv_img);
        TextView tv_title = convertView.findViewById(R.id.tv_title);
        ImageView iv_user_headimg = convertView.findViewById(R.id.iv_user_headimg);
        TextView iv_user_name = convertView.findViewById(R.id.iv_user_name);
        TextView tv_favorites = convertView.findViewById(R.id.tv_favorites);
        //根基位置得到对应的数据
        DiaryBean diaryBean = data.get(position);
        Glide.with(context).load(Constants.IMG_URL+diaryBean.getContentImg()).into(iv_img);
        tv_title.setText(diaryBean.getTitle());
        Glide.with(context).load(Constants.IMG_URL+diaryBean.getUheadImg()).into(iv_user_headimg);
        iv_user_name.setText(diaryBean.getUname());
        tv_favorites.setText(diaryBean.getPrefer());
        return convertView;
    }
}
